package com.xmu.edu.tisp.task.three;




import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.xmu.edu.tisp.R;
import com.xmu.edu.tisp.diyview.TispActivity;
import com.xmu.edu.tisp.login.TispLogin;

public class ExitConfirmDialog extends AlertDialog{
	private Context context;
	private View view;
	private Button confirmButton;
	private Button cancelButton;
	//private List<Activity> activityList;
	public ExitConfirmDialog(Context context) {
		super(context);
        this.context = context;
        
        
        
        LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		view = inflater.inflate(R.layout.cjx_exit_confirm,null);
		this.setView(view,0,0,0,0);
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);		
		
		confirmButton = (Button)view.findViewById(R.id.cjx_exit_confirm_button);
		confirmButton.setOnClickListener(
				new Button.OnClickListener(){

					@Override
					public void onClick(View arg0) {
							ExitConfirmDialog.this.dismiss();
							
							Intent intent = new Intent();
							intent.setClass(context,TispLogin.class);
							context.startActivity(intent);
							
							TispActivity.isExited = true;
							Intent home = new Intent(Intent.ACTION_MAIN);  
							home.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
							home.addCategory(Intent.CATEGORY_HOME);  
							context.startActivity(home);
					}					
				}
		);
		
		
		cancelButton = (Button)view.findViewById(R.id.cjx_exit_cancel_button);
		cancelButton.setOnClickListener(
				new Button.OnClickListener(){

					@Override
					public void onClick(View v) {
						ExitConfirmDialog.this.cancel();
					}
					
				}
		);
	}
	public Button getConfirmButton() {
		return confirmButton;
	}
	public Button getCancelButton() {
		return cancelButton;
	}
	
	public void setTitle(String title){
		TextView tv = (TextView) view.findViewById(R.id.cjx_dialog_title);
		tv.setText(title);
	}
}














